SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


CREATE VIEW dbo.[DnnProduct_vw_FolderPermissions]
AS
    SELECT     
        FP.FolderPermissionID, 
        F.FolderID, 
        F.FolderPath, 
        P.PermissionID, 
        FP.RoleID, 
        CASE FP.RoleID WHEN - 1 THEN 'All Users' WHEN - 2 THEN 'Superuser' WHEN - 3 THEN 'Unauthenticated Users' ELSE R.RoleName END AS RoleName, 
        FP.AllowAccess, 
        FP.UserID, 
        U.Username, 
        U.DisplayName, 
        P.PermissionCode, 
        P.ModuleDefID, 
        P.PermissionKey, 
        P.PermissionName, 
        F.PortalID,FP.CreatedByUserID, 
                      FP.CreatedOnDate, FP.LastModifiedByUserID, FP.LastModifiedOnDate
    FROM    dbo.DnnProduct_FolderPermission AS FP 
        LEFT OUTER JOIN dbo.DnnProduct_Folders AS F ON FP.FolderID = F.FolderID 
        LEFT OUTER JOIN dbo.DnnProduct_Permission AS P ON FP.PermissionID = P.PermissionID 
        LEFT OUTER JOIN dbo.DnnProduct_Roles AS R ON FP.RoleID = R.RoleID 
        LEFT OUTER JOIN dbo.DnnProduct_Users AS U ON FP.UserID = U.UserID
GO
